//
//  indexViewController.m
//  OC背景主题
//
//  Created by Hahn on 2018/11/1.
//  Copyright © 2018 今晚打老虎. All rights reserved.
//

#import "indexViewController.h"
#import "theme.h"
#import "UIView+theme.h"
#import "UILabel+theme.h"

@interface indexViewController ()

@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UILabel *state;
@end

@implementation indexViewController

- (void)dealloc {
    // 移除监听
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"首页";
        [self.view themeWithType:0];
    //第二种模式
//    [self.view themeWithType:1];
    [self.label themeTextType:0];
    //第二种模式
//    [self.label themeTextType:1];
    
    [self.state themeTextType:0];
}

- (IBAction)switch:(UISwitch*)sender {
    if(sender.on){
        [UIView animateWithDuration:0.3 animations:^{
            [theme shareTheme].appColor = 1;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"changeColor" object:nil];
            //修改tabbar的图标
            self.tabBarController.viewControllers[0].tabBarItem.image = [[UIImage imageNamed:@"cart-off"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.tabBarController.viewControllers[0].tabBarItem.selectedImage = [[UIImage imageNamed:@"cart-on"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.tabBarController.viewControllers[1].tabBarItem.image = [[UIImage imageNamed:@"order-off"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.tabBarController.viewControllers[1].tabBarItem.selectedImage = [[UIImage imageNamed:@"order-on"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.tabBarController.viewControllers[0].tabBarItem.title = @"首页1";
            self.tabBarController.viewControllers[1].tabBarItem.title = @"我的1";
        }];
        self.state.text = @"夜间模式";
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            [theme shareTheme].appColor = 0;
            //修改tabbar的图标
            [[NSNotificationCenter defaultCenter] postNotificationName:@"changeColor" object:nil];
            self.tabBarController.viewControllers[0].tabBarItem.image = [[UIImage imageNamed:@"home-off"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.tabBarController.viewControllers[0].tabBarItem.selectedImage = [[UIImage imageNamed:@"home-on"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.tabBarController.viewControllers[1].tabBarItem.image = [[UIImage imageNamed:@"my-off"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.tabBarController.viewControllers[1].tabBarItem.selectedImage = [[UIImage imageNamed:@"my-on"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.tabBarController.viewControllers[0].tabBarItem.title = @"首页";
            self.tabBarController.viewControllers[1].tabBarItem.title = @"我的";
        }];
        self.state.text = @"日间模式";
    }
    [[NSUserDefaults standardUserDefaults] setInteger:[theme shareTheme].appColor forKey:@"appColor"];
}


@end
